<template>
	<view class="container">
		<scroll-view scroll-y class="questions-list" @scrolltolower="loadMore">
			<view class="titles"> 
				<view class="solt"> </view>
				<view class="t"> 错题本 </view>
				<view class="tabs">
					<view class="ls left" :class="tabCur == 1 ? 'active' : ''" @click="tabs(1)"> 时间顺序 </view>
					<view class="ls right" :class="tabCur == 2 ? 'active' : ''" @click="tabs(2)"> 知识点顺序 </view>
				</view>
			</view>
			<view v-if="paperList.length>0" style="padding-bottom: 40rpx;">
				<view class="list" v-for="(item, index) in paperList" :key="item.id">
					<view class="contents" v-if="tabCur == 1" @click="answer(item)" hover-class="bg-click">
						<view class="paper-header">
							<text class="title">{{item.question_title}}</text>
						</view>
						<view class="right">
							<image src="/static/rights.png" class="rights" mode=""></image>
						</view>
					</view>
					<view class="contentsss" v-if="tabCur == 2" @click="toggleAccordion(index)">
						<view class="paper-header">
							<text class="title">{{item.paper.title}}</text>
						</view>
						<view class="right">
							<image src="/static/rights.png" class="rights" mode=""></image>
						</view>
					</view>
					<view class="accordion-content" :style="{ maxHeight: activeIndex === index ? maxHeight + 'px' : '0' }"  hover-class="bg-click">
						<view class="detail" v-for="(items,key) in item.answer_list" @click="answer(items)">
							<view class="paper-header" style="padding-bottom: 10rpx;">
								<text class="title">{{items.question_title}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view v-else class="nodata">暂无数据</view>
			<!-- 加载状态 -->
			<view class="loading-status">
				<text v-if="isLoading" class="loading-text">加载中...</text>
				<text v-if="!noMore" class="no-more">没有更多了~</text>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseURL: getApp().globalData.baseUrl,
				appid: uni.getStorageSync('appid'),
				paperList: [],
				currentPage: 1,
				noMore: false,
				isLoading: false,
				total: 0,
				tabCur: 1,
				maxHeight: 3000,
				activeIndex: -1
			}
		},
		onShow(){
			this.tabCur  = 1,
			this.getList()
		},
		methods: {
			loadMore() {
			  if (this.isLoading || this.noMore) return
			  this.currentPage += 1
			  this.getList()
			},
			getList(){
				uni.request({
					url: this.baseURL + '/api/paper/wrongSheet',
					method: 'GET',
					data: {appid:this.appid,page:this.currentPage},
					header: { 'Content-Type': 'application/json' },
					success: (res) => {
						this.total  = res.data.data.total
						if( res.data.status == 100 ){
							this.searchShow =  false
							if (this.currentPage === 1) {
								this.paperList = res.data.data.data
							} else {
								this.paperList = [...this.paperList, ...res.data.data.data]
							}
							this.isLoading = false
							if( this.currentPage <= res.data.data.last_page ){
								this.noMore = false
							} else {
								this.noMore = true
							}
						}
					},
					fail: (err) => {
						console.error('请求失败:', err);
					}
				})
			},
			getLists(){
				console.log(this.appid)
				uni.request({
					url: this.baseURL + '/api/paper/wrongSheetByGroup',
					method: 'GET',
					data: {appid:this.appid,page:this.currentPage},
					header: { 'Content-Type': 'application/json' },
					success: (res) => {
						console.log("res.datares.datares.datares.datares.data",res.data)
						this.total  = res.data.data.total
						if( res.data.status == 100 ){
							this.searchShow =  false
							if (this.currentPage === 1) {
								this.paperList = res.data.data.data
							} else {
								this.paperList = [...this.paperList, ...res.data.data.data]
							}
							this.isLoading = false
							if( this.currentPage <= res.data.data.last_page ){
								this.noMore = false
							} else {
								this.noMore = true
							}
						}
					},
					fail: (err) => {
						console.error('请求失败:', err);
					}
				})
			},
			answer(item){
				uni.setStorageSync('timu',item)
				uni.navigateTo({url: '/pages/question/cuoti_a'})
			},
			tabs(index){
				this.tabCur = index
				if( index == 1 ){
					this.getList()
				} else if( index == 2 ){
					this.getLists()
				}
			},
			toggleAccordion(index) {
				console.log(111111)
				this.activeIndex = this.activeIndex === index ? -1 : index;
			},
		}
	}
</script>

<style>
	.container {height: 100vh;width: 100%;background: #f2f2f2;}
	.questions-list{height: 100%;margin: 0rpx auto;}
	.titles{padding: 20rpx 30rpx;display: flex;flex-direction: row;align-items: center;background: #fff;}
	.solt{width: 15rpx;height: 15rpx;background: #BEBEBE;}
	.titles .t{margin-left: 10rpx;font-size: 30rpx;font-weight: bold;}
	.list{background: #fff;}
	.contents{width: 90%;margin: 0 auto;display: flex;flex-direction: row;padding: 20rpx;border-bottom: 1rpx solid #BEBEBE;}
	.contentsss{width: 90%;margin: 0 auto;display: flex;flex-direction: row;padding: 20rpx;border-bottom: 1rpx solid #BEBEBE;}
	.detail .paper-header{border-bottom: 1rpx solid #BEBEBE;}
	.right{width: 20rpx;height: 30rpx;}
	.right .rights{width: 20rpx;height: 30rpx;}
	.paper-header{width: 100%;}
	.paper-header .title{font-size: 28rpx;color: #81A1BE;}
	.desc{display: flex;flex-direction: row;margin-top: 10rpx;}
	.paper-info .questions{font-size: 24rpx;color: #B9B9B9;}
	.paper-meta{margin-left: 20rpx;}
	.paper-meta .score{font-size: 24rpx;color: #B9B9B9;}
	.bg-click{background: #ebebeb;}
	.nodata{width: 100%;text-align: center;color: #999;padding-top: 50rpx;}
	.loading-status {text-align: center;padding: 30rpx 0;}
	.loading-text {color: #888;font-size: 28rpx;}
	.no-more {color: #ccc;font-size: 28rpx;}
	scroll-view ::-webkit-scrollbar {display: none;width: 0;height: 0;color: transparent;}
	.tabs{width: 300rpx;border: 1rpx solid red;display: flex;flex-direction: row;position: absolute;right: 30rpx;border-radius: 50rpx;line-height: 50rpx;justify-content: space-around;}
	.tabs view{font-size: 26rpx;text-align: center;width: 50%;height: 50rpx;}
	.tabs .left{border-top-left-radius: 50rpx;border-bottom-left-radius: 50rpx;}
	.tabs .right{border-top-right-radius: 50rpx;border-bottom-right-radius: 50rpx;}
	.tabs .active{background-color: #F56822;color: #fff;}
	.accordion-content {overflow: hidden;transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);padding: 0 15px;background-color: #fff;border-top: 1px solid #eee;}
	.accordion-content > view {padding: 10rpx 0;}
</style>
